//
//  LPZWYHomeMustTableViewCell.m
//  ZhongWangYuanApp
//
//  Created by liuyingping on 2018/6/5.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "LPZWYHomeMustTableViewCell.h"
#import "LPWYHomeMustCellView.h"
@implementation LPZWYHomeMustTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

   
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
       
    }
    return self;
}


- (void)setDataSouce:(NSArray *)dataSouce{
    _dataSouce = dataSouce;
    
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[LPWYHomeMustCellView class]]) {
            [view removeFromSuperview];
        }
    }
    
    for (int i = 0; i < dataSouce.count; i ++) {
        
        NSInteger yu = i % 2;
        NSInteger zheng = i / 2;
        CGFloat width = ([UIScreen zj_screenWith] - 30 * [UIScreen zj_screenWScale])  / 2;
        LPWYHomeMustCellView *cellView = [[LPWYHomeMustCellView alloc] initWithFrame:CGRectMake(10 * [UIScreen zj_screenWScale] + (width + 10 * [UIScreen zj_screenWScale]) * yu, 170 * [UIScreen zj_screenHScale] * zheng, width, 150 * [UIScreen zj_screenHScale])];
        cellView.userInteractionEnabled = YES;
        cellView.tag = i;
        [self addSubview:cellView];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapView:)];
        [cellView addGestureRecognizer:tap];
        LPZWYChooseClassClassModel *model = dataSouce[i];
        
        [cellView.topImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@" , CREATEURL(model.image_servername)]] placeholderImage:PlaceholderImage];
        
        cellView.mustLabel.text = [NSString stringWithFormat:@"必修: %.1f学时",[model.requiredstudytime floatValue]];
        
         cellView.optionalLabel.text = [NSString stringWithFormat:@"选修: %.1f学时",[model.electivestudytime floatValue]];
        cellView.applyLabel.text = [NSString stringWithFormat:@"已报名人数: %@",model.signnumber];
    }
}

- (void)tapView:(UITapGestureRecognizer *)tap{
    if (self.delegate) {
        [self.delegate LPZWYHomeMustTableViewCell_clickViewIndex:tap.view.tag section:self.section];
    }
}


@end
